<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Cache;
use think\Session;
use think\response\Json;
class Order extends Controller{

    //订单显示列表
    public function index(){
        $id = Session::get("USERS.user_id");

        $row = Db::table("orders")->where("is_del = 0 and user_id = $id and order_status = 2")->select();
        $res = Db::table("orders")->where("is_del = 0 and user_id = $id and order_status = 0")->select();
        $this->assign("row",$row);
        $this->assign("res",$res);
        return view();

    }

    //订单写入
    public function orderInsert(){

        $request = Request::instance()->post();
        $data = array();
        $data['courses_id'] = $request['courses_id'];
        $data['total_money'] = $request['total_money'];
        $data['user_id'] = Session::get("USERS.user_id");
        $data['order_status'] = 2;
        $data['is_pay'] = 1;
        $data['order_type'] = 1;
        $data['is_del'] = 0;
        $data['order_time'] = time();

//        echo json_encode($data);
//        exit;

        $res = Db::table("orders")->insert($data);

        echo json_encode($res);


    }



}